import { defineStore } from 'pinia';
import { lifeMilestone } from '@/services/apis';
import { isEmpty } from 'lodash'
import { convertToLifeMilestone, parseLifeMilestone } from './utils/lifeMilestone'

export const useLifeMilestoneStore = defineStore('lifeMilestone', {
    state: () => ({

    }),
    actions: {
        async add(params: any, isClean = false) {
            if (isClean) {
                await this.clean();
            }
            await lifeMilestone.add(convertToLifeMilestone(params));
        },
        async list(params: any) {
            try {
                const res = await lifeMilestone.list({
                    orderByColumn: 'milestoneDate',
                    isAsc: 'desc',
                    ...params
                });
                return parseLifeMilestone(res)
            } catch (error) {
                return []
            }
        },
        // async edit(params: any) {
        //     await yearlyFortune.edit(params);
        // },
        async getMilestoneTypeList(params) {
            return await lifeMilestone.life_milestones_type(params)
        },
        async clean() {
            await lifeMilestone.clean()
        },
        async remove(params) {
            await lifeMilestone.delete(params)
        }
        // async save(params: any) {
        //     if (params.type === 'add') {
        //         await this.add([params])
        //     } else {
        //         await this.edit(params)
        //     }
        // }
    }
})